﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class TinhThanhInfo
    {
        private string _TinhThanhID;

        public string TinhThanhID
        {
            get { return _TinhThanhID; }
            set { _TinhThanhID = value; }
        }

        private string _TenTinhThanh;

        public string TenTinhThanh
        {
            get { return _TenTinhThanh; }
            set { _TenTinhThanh = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class TinhThanhCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(TinhThanhInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@TinhThanhID", Item.TinhThanhID),
                new SqlParameter("@TenTinhThanh", Item.TenTinhThanh == null ? (object)DBNull.Value:Item.TenTinhThanh),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_TinhThanh_Insert", Para);
        }

        public void Update(TinhThanhInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@TinhThanhID", Item.TinhThanhID),
                new SqlParameter("@TenTinhThanh", Item.TenTinhThanh == null ? (object)DBNull.Value:Item.TenTinhThanh),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_TinhThanh_Update", Para);
        }

        public void Delete(string strTinhThanhID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@TinhThanhID", strTinhThanhID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_TinhThanh_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_TinhThanh_GetList");
            return Ds.Tables[0];
        }

        public TinhThanhInfo GetByID(string strTinhThanhID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_TinhThanh_Get", new SqlParameter("TinhThanhID", strTinhThanhID));
            TinhThanhInfo ObjTinhThanh = null;
            while (dtr.Read())
            {
                ObjTinhThanh = new TinhThanhInfo();
                ObjTinhThanh.TinhThanhID = dtr["TinhThanhID"].ToString();
                ObjTinhThanh.TenTinhThanh = dtr["TenTinhThanh"].ToString();
                ObjTinhThanh.Active = (bool)dtr["Active"];
            }
            return ObjTinhThanh;
        }
    }
}
